﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Text;

namespace Admx_Generator
{
    public class ComboBoxPresentation : IPresentationElement
    {
        public ComboBoxPresentation(string refId, string label)
        {
            this.RefId = refId;
            this.NoSort = false;
            this.Label = label;
            this.Default = String.Empty;
            this.Suggestion = new List<string>();
        }

        private string RefId { get; set; }
        private bool NoSort { get; set; }
        private string Label { get; set; }
        public string Default { get; set; }
        public List<string> Suggestion { get; private set; }


        public void Save(XmlWriter xmlWriter)
        {
            // comboBoxPresentation
            xmlWriter.WriteStartElement("comboBoxPresentation");
            xmlWriter.WriteAttributeString("refId", this.RefId);
            xmlWriter.WriteAttributeString("noSort", this.NoSort.ToString().ToLower());
            // label
            xmlWriter.WriteStartElement("label");
            xmlWriter.WriteString(this.Label);
            xmlWriter.WriteEndElement(); // label
            if(!String.IsNullOrEmpty(this.Default))
            {
                // default
                xmlWriter.WriteStartElement("default");
                xmlWriter.WriteString(this.Default);
                xmlWriter.WriteEndElement(); // default
            }
            if(this.Suggestion.Count > 0)
            {
                // suggestion
                foreach (string suggestion in this.Suggestion)
                {
                    xmlWriter.WriteStartElement("suggestion");
                    xmlWriter.WriteString(suggestion);
                    xmlWriter.WriteEndElement(); // suggestion
                }
            }
            xmlWriter.WriteEndElement(); // comboBoxPresentation
        }
    }
}
